import * as TYPES from './actionTypes';
import {ProfileGetUrl,ProfileInfoUrl,ProfileUpdateUrl,ProfileSpecial,ProfileChangeUrl} from '../../Component/common/url';

// PROFILEALL
export function ProfileAll(token){
	return (dispatch) => {
		let order_all = fetch(ProfileGetUrl,{
				method: "POST",
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer "+token
				},
				body:JSON.stringify({authState:["pass","pending","noPass"]})
			})
			.then(response=>response.json())
			.then((data)=>{
				dispatch({'type': TYPES.PROFILE_GET, profile: data});
			}).catch((e)=>{
				console.log(e.message);
				//dispatch({'type': TYPES.SIGN_ERRER, error: e});
			});
	}
}
// PROFILEPENDING
export function ProfilePending(token){
	return (dispatch) => {
		let order_all = fetch(ProfileGetUrl,{
				method: "POST",
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer "+token
				},
				body:JSON.stringify({authState:["pending"]})
			})
			.then(response=>response.json())
			.then((data)=>{
				dispatch({'type': TYPES.PROFILE_GET, profile: data});
			}).catch((e)=>{
				console.log(e.message);
				//dispatch({'type': TYPES.SIGN_ERRER, error: e});
			});
	}
}
// PROFILEPASS
export function ProfilePass(token){
	return (dispatch) => {
		let order_all = fetch(ProfileGetUrl,{
				method: "POST",
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer "+token
				},
				body:JSON.stringify({authState:["pass"]})
			})
			.then(response=>response.json())
			.then((data)=>{
				dispatch({'type': TYPES.PROFILE_GET, profile: data});
			}).catch((e)=>{
				console.log(e.message);
				//dispatch({'type': TYPES.SIGN_ERRER, error: e});
			});
	}
}
// PROFILENOPASS
export function ProfileNopass(token){
	return (dispatch) => {
		let order_all = fetch(ProfileGetUrl,{
				method: "POST",
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer "+token
				},
				body:JSON.stringify({authState:["noPass"]})
			})
			.then(response=>response.json())
			.then((data)=>{
				dispatch({'type': TYPES.PROFILE_GET, profile: data});
			}).catch((e)=>{
				console.log(e.message);
				//dispatch({'type': TYPES.SIGN_ERRER, error: e});
			});
	}
}
//GETUSERPROFILE
export function ProfileInfo(token){
	return (dispatch) => {
		let inner_get = fetch(ProfileInfoUrl,{
				method: "POST",
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer "+token
				},
				//body:JSON.stringify(opt)
			})
			.then(response=>response.json())
			.then((data)=>{
				dispatch({'type': TYPES.PROFILE_INFO, 'userinfo': data});
			}).catch((e)=>{
				console.log(e.message);
				//dispatch({'type': TYPES.SIGN_ERRER, error: e});
			});
	}
}
//UPDATEUSERPROFILE
export function ProfileUpdate(token,opt){
	return (dispatch) => {
		let inner_get = fetch(ProfileUpdateUrl,{
				method: "POST",
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer "+token
				},
				body:JSON.stringify(opt)
			})
			.then(response=>response.json())
			.then((data)=>{
				dispatch({'type': TYPES.PROFILE_INFO, 'userinfo': data});
			}).catch((e)=>{
				console.log(e.message);
				//dispatch({'type': TYPES.SIGN_ERRER, error: e});
			});
	}
}
//DETAIL_PROFILE
export function ProfileDetail(token,opt){
	return (dispatch) => {
		let inner_get = fetch(ProfileSpecial,{
				method: "POST",
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer "+token
				},
				body:JSON.stringify(opt)
			})
			.then(response=>response.json())
			.then((data)=>{
				dispatch({'type': TYPES.PROFILE_DETAIL, 'special': data});
			}).catch((e)=>{
				console.log(e.message);
				//dispatch({'type': TYPES.SIGN_ERRER, error: e});
			});
	}
}
//CHANGE_SPECIAL_PROFILE
export function ProfileChange(token,opt){
	return (dispatch) => {
		let inner_get = fetch(ProfileChangeUrl,{
				method: "POST",
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer "+token
				},
				body:JSON.stringify(opt)
			})
			.then(response=>response.json())
			.then((data)=>{
				dispatch({'type': TYPES.PROFILE_DETAIL, 'special': data});
			}).catch((e)=>{
				console.log(e.message);
				//dispatch({'type': TYPES.SIGN_ERRER, error: e});
			});
	}
}